perm filename APPEND.NEW[TEX,RWF]1 blob sn#536185 filedate 1980-09-19 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00007 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\appendix A. {Introduction to the TOPS-20 System at LOTS}
C00009 00003	\appendix B. {File Protection}
C00013 00004	\appendix C. {More TOPS-20 Commands}
C00026 00005	\appendix D. {Number Representation of DEC System-20 and Relations to Pascal}
C00053 00006	\appendix E. {Finding the Root of an Equation}
C00057 00007	\appendix F. {Numerical Calculus}
C00068 ENDMK
C⊗;
\appendix A. {Introduction to the TOPS-20 System at LOTS}
\sendindex{Appendices}

How to do some common tasks at LOTS.

Notation:  A {\↑C} means you should hold down the {\tt CTRL} (pronounced control) key
on the keyboard while typing the letter C.
The {\esc} sign means the ESC (pronounced escape) key.
The \return \ symbol is the RETURN key.
Underlined characters are the ones you type; you may sometimes
have to wait for the others to be automatically printed by the computer.

\vskip 10pt

\bitem  To log in:
\type{}>{\↑C}
\type{system messages}>{}
\type{\@}>{LOGIN\esc\ {\sl user-name}\esc {\sl password}\return}
\leveltwo{$\→$}  {\sl user-name} is your name as known to the system.
\leveltwo{$\→$}  {\sl password} is your password.
\bitem  To log out:
\type{\@}>{LOGOUT\return}
\type{system messages}>{}
\bitem  To delete a partially typed line:
\type{}>{\↑U}
\bitem  To delete the last character you typed:
\type{}>{\bs\  or {\tt DEL} or {\tt RUB}, depending on your keyboard}
\bitem  To type in a Pascal program or other material as a new file:
\type{\@}>{CREATE\esc\ {\sl file}\return}
\leveltwo{$\→$}  {\sl file} is your file name
\leveltwo{$\→$}  The system will echo your file name and then accept your text
%DPB-don't know if they write the underlined or the system does at LOTS
%DPB-don't know what first line or second line means
\type{00100}>{\ {\sl your first line}\return}
\type{00200}>{\ {\sl your second line}\return}
\type{.}>{}
\type{.}>{}
\type{.}>{}
\type{line number}>{\ {\sl your last line}\return}
\type{line number}>{\esc}
\type{*}>{E\return}
\type{\@}>{}
\bitem  To scrap the whole thing in the middle and start over, use the
{\tt EQ} command to exit instead of the {\tt E} command.  That is:
\type{line number}>{\ {\sl your last line}\return}
\type{line number}>{\esc}
\type{*}>{EQ\return}
\type{\@}>{CREATE {\sl etc.}}
\bitem  To run a Pascal program (its name should end in .PGO)
\type{\@}>{EXECUTE\esc\ {\ {\sl file}\return}}
\type{system messages}>{}
\type{output from your program}>{}
\type{system messages about termination of your program}>{}
\type{\@}>{}
\bitem  To stop your program while it is running:
\type{}>{\↑C \ \↑C}
\type{\@}>{}
\bitem  To correct or change a program that has been filed, e.g. by a previous CREATE:
\type{\@}>{EDIT\esc{\sl file }\return}
%\type{*{\sl editing commands} -- see summary below}>{}
\type{editing commands -- see summary below}>{}
\type{*}>{E\return}
\type{\@}>{}
\bitem  To get a printed copy of a file:
\type{\@}>{PRINT\esc {\sl file}\return}
\type{system echo}>{}
\bitem  To read a file:
\type{\@}>{TYPE\esc {\sl file}\return}
\bitem To move forward through a file you are reading:
\type{\↑Q}>{}
\bitem  Summary of things to say to EDIT:
\leveltwo{$\→$}  To see a particular line (or lines) of the file you are editing:
\type{*}>{P {\sl line number}\return}
%DBP-I don't think the next line is necessary and it's confusing
\type{the line having that number}>{}
\type{*}>{}
(Note:  For more than one line, use the first and last line numbers, with a colon between them.)
\leveltwo{$\→$}  To insert a line between existing lines, using an intermediate line number:
\type{*}>{I {\sl line number}\return}
\type{line number}>{\ {\sl your new line}}
\type{*}>{}
\leveltwo{$\→$}  To delete one or more lines of the file:
\type{*}>{D {\sl line number(s)}\return}
\type{system echo}>{}
\type{*}>{}
\leveltwo{$\→$}  To replace a line of the file with a new one:
\type{*}>{R {\sl line number}\return}
\type{line number}>{\ {\sl your new line}}
\type{system echo}>{}
\type{*}>{}
\leveltwo{$\→$}  To change APPLE to BANANA in a line of your file:
\type{*}>{SAPPLE\esc BANANA\esc\ {\sl line number}\return}
\type{line number \ \ the line as modified}>{}
\leveltwo{$\→$}  To save the edited file and return to talking to TOPS 20:
\type{*}>{E\return}
\type{\@}>{}


\appendix B. {File Protection}
\sendindex{File Protection}

     Unless you take some action to protect your files, they can be read or
copied by anyone.  This is inapropriate for course assignments, in a world
where not everyone is honest.  To change the protection status of a file, 
use the TOPS-20 command 

\type {\@}>{SET FILE PROTECTION {\sl filename n}}
\noindent
where  {\sl n} is a six digit number, say  AABBCC.  Here the two digits  AA
control what you  yourself can do to the file,  BB  control what members of
your ``group'' can do (meaningless for courses),
and  CC  controls what everyone else can do to your file.

    Each of these two digit numbers is obtained by adding up codes for the
capabilities you want to allow, according to this code:
 
\startcode
        40  Allow reading.
        20  Allow writing (i.e., changing the file, possibly 
            losing its current contents).
        10  Allow executing.
        04  Allow appending to the file.
        02  Allow appearance in directory listings.
        01  Has no effect.
\endcode

If you don't protect a file, it has protection number   777752,
so anyone can read or execute it or see that it is
in your directory; only you can change or add to it.  A more appropriate
protection number for homework Pascal programs is  777702.
You may at times want to protect your files even from yourself, to prevent
unintentional erasing.

     You can set the protection for all files you create in the future by
the TOPS-20 command

\type {\@}>{SET DIRECTORY FILE-PROTECTION-DEFAULT {\sl username n}}
\noindent
where {\sl n} is again the protection number.  This command does not affect
present
or future generations of existing files.  It does not prevent you from changing
the protection numbers on individual files after creating them.

     For more details, see {\sl LOTS DEC System-20 Overview}, section 2.5.2.1
\appendix C. {More TOPS-20 Commands}
\sendindex{More TOPS-20 Commands}

How to do some common tasks in file handling at LOTS.

\vskip 14pt

\bitem  Getting information about the system.
\leveltwo{$\→$}  Information about a TOPS-20 command:
\type{\@}>{HELP {\sl command-name}\return}
\leveltwo{$\→$}  Information about what you can type next:
\type{}>{\esc}
\type{or}>{}
\type{}>{?}
\leveltwo{$\→$}  Information about files.
\levelthree{$\→$}  To see what files you have (names only):
\type{\@}>{DIRECTORY \return}
\levelthree{$\→$}  To see more detailed information about those files (protection states, pages, size, date):
\type{\@}>{VD \return}
\levelthree{}(stands for ``verbose directory'')
\levelthree{$\→$}  To see such information about a subset of your directory, or about another directory:
\type{\@}>{DIRECTORY\esc  {\sl files}\return}
\levelthree{}(similar for VD)
\levelthree{$\→$}  To see which files have been deleted but not yet expunged:
\type{\@}>{QDIRECTORY\return}
\levelthree{$\→$}  To see general information about a directory:
\type{\@}>{INFO\esc  DIRECTORY\esc  {\sl <directory name>} \return}
\levelthree{}or, for more detail,
\type{\@}>{INFO\esc  DIRECTORY\esc  {\sl <directory name>,} \return}
\type{\@\@}>{VERBOSE\return}
\type{\@\@}>{\return}
\leveltwo{$\→$}  Information about the system, and your program, if you have one running:
\type{}>{\↑T}
\leveltwo{$\→$}  Information about what files are waiting to be printed (yours and
others'), showing job names, sequence numbers, sizes, and user names:
\type{\@}>{INFORMATION\esc  OUTPUT-REQUESTS\return}
\leveltwo{$\→$}  Information about the current time and date:
\type{\@}>{DAYTIME\return}
\leveltwo{$\→$}  Information about your terminal time allocation:
\type{\@}>{INFORMATION\esc ALLOCATION\return}
%ok to here
\bitem  Making permanent changes in the system conventions for handling 
your files and jobs:
\type{\@}>{SET  ...}
\levelone{}  is used for most such changes.
\levelone{}  Some important cases of SET follow.  To see what conventions are
in effect for you, use the INFO commands.
\sendnotes{RWF-In your notes you wrote "Checkout??????==>" the section To }
\sendnotes{change the number of generations kept in your files:}
\leveltwo{$\→$}  To change the number of generations kept in your files:
\type{\@}>{SET\esc  DIRECTORY\esc  GENERATION\esc  {\sl directory-name\esc number}\return}
\type{\tt PASSWORD:}>{Your password\esc}
\leveltwo{$\→$}  To change the level of protection of directory information:
\type{\@}>{SET\esc  DIRECTORY\esc  PROTECTION\esc  {\sl directory-name\esc number}\return}
\type{\tt PASSWORD:}>{Your password}
\leveltwo{$\→$}  To change the level of protection automatically given to files you create in the future:
\type{\@}>{SET\esc  DIRECTORY\esc  FILE-PROTECTION-DEFAULT\esc {\sl directory-name}\esc {\sl number}\return}
\leveltwo{$\→$}  See also printing format defaults, and initialization files.
\bitem  Correcting mistakes.
\leveltwo{$\→$}  To cancel a printing request:
\type{\@}>{CANCEL\esc  PRINT\esc  {\sl jobname}\return}
\leveltwo{} or
\type{\@}>{CANCEL\esc  PRINT\esc  /SEQ\esc  {\sl sequence number}\return}
\leveltwo{$\→$} To cancel all your current print requests:
\type{\@}>{CANCEL\esc  PRINT\esc  {\tt *}\return}
\leveltwo{$\→$}  To retrieve deleted files:
\type{\@}>{UNDELETE\esc  {\sl files}\return}
\leveltwo{}(use generation number)
\leveltwo{$\→$}  To change switch settings on a pending print request:
\sendnotes{FINALCHECK - see if help modify looks right.}
%\type{\@}>{MODIFY\esc  PRINT\esc ...}
{\par\indpar{\tt \@\under{MODIFY\esc  PRINT\esc ...}\quad {\rm (see}\ 
\@\under{{\tt HELP}\esc {\tt MODIFY}\return}\ {\rm or}\ 
\@\under{{\tt HELP}\esc {\tt PRINT}\return}{\rm)}
}\par}
\bitem  Sending messages.
\leveltwo{$\→$}  To send mail to another user.
\type{\@}>{MAIL {\sl username}\return}
\type{SUBJECT:}>{one line title\return}
\type{MESSAGE:}>{as many lines as you like}
\type{}>{terminated with \↑Z.}
\leveltwo{}  You can also send mail to or from files ---  see {\tt \@\under{HELP\esc  MAIL\return}}
\leveltwo{$\→$}  To read your mail:
\type{\@}>{TYPE  MAIL.TXT\return}
\leveltwo{$\→$}  To delete all mail:
\type{\@}>{DELETE MAIL.TXT\return}
\leveltwo{$\→$}  To delete part of your mail (and for general information about mail):
\type{\@}>{HELP  MM\return}
\leveltwo{$\→$}  To send a message to someone at another terminal:
\type{\@}>{SEND\esc  username\esc  one-line-message\return}
\leveltwo{}  To send a long message:
\type{\@}>{NSEND\return}
\leveltwo{} or
\type{\@}>{HELP NSEND\return}
\bitem Printing.
\leveltwo{$\→$}  To limit printing to n pages:
\type{\@}>{PRINT\esc  files\esc  /LIMIT:  n\return}
\leveltwo{$\→$}To insert a note, up to 12 characters, in output header:
\type{\@}>{PRINT\esc  files\esc  /NOTE:  text of note\return}
\leveltwo{$\→$}Tp print some files at a specified later time (e.g., late at night):
\type{\@}>{PRINT\esc  files\esc  /AFTER: ...}
\sendnotes{==>RWF-can't put all on one line because of macro}
\leveltwo{}(see \@\under{{\tt HELP}\esc {\tt PRINT}\return}
%\leveltwo{$\→$}To print, starting at line n of a file:
%\type{\@}>{PRINT\esc  files\esc  /COPIES:  n\return}
\leveltwo{$\→$}To print and then delete a file:
\type{\@}>{PRINT\esc  files\esc  /DELETE\return}
\leveltwo{$\→$}To print binary files, in octal:
\type{\@}>{PRINT\esc  files\esc  /PRINT:  OCTAL\return}
\sendnotes{How to print suppressing control characters?Check at LOTS}
%\leveltwo{$\→$}To print, suppressing control characters (form feed, tab, etc.) except {\tt CR} and {\tt LF}:
%\type{\@}>{PRINT\esc  files\esc  /SPACING:  SUPPRESS\return}
\leveltwo{$\→$}To print double or triple-spaced:
\type{\@}>{PRINT\esc  files\esc  /SPACING:  DOUBLE\return}
\type{\@}>{PRINT\esc  files\esc  /SPACING:  TRIPLE\return}
%\leveltwo{}(watch out for changes in this command)
\leveltwo{$\→$}To automatically include the above switches, like {\tt /LIMIT:} n , in your
print commands:
\type{\@}>{SET\esc  DEFAULT\esc  PRINT\esc  /switch\return}
\leveltwo{$\→$}To clear all such automatic switches:
\type{\@}>{SET\esc  NO\esc  DEFAULT\esc PRINT\return}
\bitem Handling programs.
\levelone{}({\tt COMPILE}, {\tt LOAD}, {\tt RUN}, {\tt EXECUTE}, etc.)
\leveltwo{$\→$}To stop a PASCAL (or any other) program while it is executing:
\type{}>{\↑C}
\leveltwo{$\→$}To restart it where it left off:
\type{\@}>{CONTINUE\return}
\bitem Handling files.
\leveltwo{$\→$}To copy filesa, calling the copy fileb:
\type{\@}>{COPY\esc  filesa\esc  fileb\return}
\leveltwo{$\→$}To append filesa \ to fileb \ (useable only for files without line numbers):
\type{\@}>{APPEND\esc  filesa\esc  fileb \ \return}
\leveltwo{$\→$}To delete files from directory:
\levelthree{}(Use this cautiously!)
\type{\@}>{DELETE\esc  files \return}
\leveltwo{$\→$} To try to restore erroneously deleted files:
\type{\@}>{UNDELETE\esc {\sl files}\return}
\leveltwo{$\→$}To erase deleted files:
\type{\@}>{EXPUNGE \return}
\leveltwo{$\→$}To compare two files (see \@\under{{\tt HELP SRCCOM}\return})
\type{\@}>{SRCCOM\return}
%\levelone{VIII.}Editing files.
%\leveltwo{A.}To renumber lines and edit a file:
%\type{\@}>{EDIT  /UNSEQUENCES\esc  file\return}
%\leveltwo{B.}To create or edit a file with line numbers increasing by n:
%\type{\@}>{\left( CREATE\esc\overEDIT\esc \right) \ /INCREMENT:  N\ESC FILE\RETURN}
%\leveltwo{C.}To create or edit a file, saving a backup copy after each n inserted lines:
%\type{\@}>{\left( CREATE\esc\overEDIT\esc \right) \ /ISAVE: \ n\esc \ file\return}
\bitem  Using other directories.
\leveltwo{$\→$}To work primarily in a particular directory (see \@\under{{\tt HELP}\esc  {\tt CONNECT}\return})
\type{\@}>{CONNECT\esc  {\sl directory-name}\return}
\leveltwo{$\→$}To authorize yourself to use directory {\sl dir} (see Users' Guide Part II):
\type{\@}>{ACCESS\esc  {\sl <dir>}\return}

\bitem  To get some TOPS-20 commands automatically executed when you log
in and log out, put them into files named, respectively, {\tt LOGIN.CMD} and
{\tt LOGOUT.CMD}.  Obvious candidates for automatic commands on login are
{\tt DIRECTORY}, {\tt DAYTIME}, {\tt TYPE MAIL.TXT}, and {\tt DELETE MAIL.TXT},
{\tt SET DEFAULT PRINT}.

\appendix D. {Number Representation of DEC System-20 and Relations to Pascal}
\ctrline{by John G. Herriot}

All numbers are stored in 36-bit words.  The 36 bits of a word are numbered from
0 to 35, from left to right, just to identify them.

\sendindex{Integers}
\sneakhead{Integers}
	
Of the 36 bits in a word, bit 0 (the leftmost bit) represents the sign:  0 for 
positive and 1 for negative.  In a positive number the remaining 35 bits are the 
magnitude of the number stored in a binary (base 2) representation.  For 
example, $21↓{10}$ (the subscript means base 10, i.e., a decimal number) is stored
as $$\eqalign{⊗000\ 000\ 000\ 000\ 000\ 000\ 000\ 000\ 000\ 000\ 010\ 101\cr
	      ⊗\up\cr
	      ⊗sign\ bit\cr}$$
(The digits are conventionally written in groups of three for ease of reading.
This grouping has no significance for the actual binary representation.)  To
check this note that
$${21=\underline{0}\times2↑{34}+\cdots+\underline{0}\times2↑{5}+\underline{1}
\null\times2↑{4}+\underline{0}\times2↑{3}+\underline{1}\times2↑{2}+\underline{0}
\null\times2↑{1}+\underline{1}\times2↑{0}}.$$  

The largest positive integer which can be stored in a word is
$$2↑{34}+2↑{33}+\cdots+2↑{1}+2↑{0}=2↑{35}-1=34359738367↓{10}.$$  Any attempt to
create or store an integer larger than $2↑{35}-1$ will produce erroneous
results and the user will not always be warned of the error.  Zero is 
represented by a word containing all 0s.

To save space in writing words on paper, each group of 3 bits is frequently
converted to a single base-8 (octal) digit, according to the following code:

%Change to \vbox{\halign....}
$$\vbox{\halign{\ctr{#}⊗\qquad\ctr{#}⊗\qquad\ctr{#}⊗\qquad\ctr{#}\cr
{\under{base 2}}⊗{\under {base 8}}⊗{\under {base 2}}⊗{\under {base 8}}\cr
000⊗0⊗100⊗4\cr
001⊗1⊗101⊗5\cr
010⊗2⊗110⊗6\cr
011⊗3⊗111⊗7\cr}}$$

However, integers are actually stored as base-2 numbers.

Using octal notation, the decimal number 21 is represented by $000000000025↓8$.
Note that $25↓8$ is the octal representation of $21↓{10}$.

Negative numbers have a sign bit of 1 and are stored in what is called ``two's 
complement form''.  First we define the {\sl one's complement} of a number in
binary form as the result obtained by changing every 0 to 1 and every 1 to 0.  
The {\sl two's complement} of a number in binary form is obtained by taking the 
one's complement of the portion of the number to the left of the lowest order 
1 and leaving the rest of the number unchanged.  Notice that taking the two's
complement of the two's complement of a number restores the original number.  
For example $-1$ is stored as

$$111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111$$

\noindent
which may be written as $777777777777↓8$.  Also, $-21$ is stored as

$$111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 101\ 011$$

\noindent
To check this, note one can take the two's complement of this number, obtaining
the representation for +21 which can be evaluated as previously explained.
Alternatively one can regard the value of the sign bit as $-2↑{35}$ and give
the other digits their conventional values.  Thus
$$-2↑{35}+\underline{1}\times2↑{34}+\cdots+\underline{1}\times2↑5+\underline{0}
\null\times2↑4+\underline{1}\times2↑3+\underline{0}\times2↑2+\underline{1}\times
\null2↑1+\underline{1}\times2↑0=-21$$.

\noindent
The smallest integer which can be stored in the DEC System-20 is 
$$-2↑{35}=-34359738368↓{10}$$ 
and it is represented by $400000000000↓8$.  Note
that it cannot be produced by negating any positive number and that its 
magnitude is one greater than the largest positive number.  Remembering that
zero is represented by all 0's, we see that taking the negative of this number
means that no change is made because there is no digit 1.  Thus there is only
one zero representation and its sign is positive.

Another way to think of the representation of negative numbers is to consider
a 36-place binary accumulating register (the base-2 equivalent of the decimal
accumulating register in a small mechanical calculator).  
If one starts with all zeros
in their register, one gets the representation for $-1$ by subtracting 1.  The
process requires a ``borrow'' to propagate to the left all the way across
the register, leaving all ones, just as on a decimal calculator this would
leave all nines.  Continued subtractions will give the representations for 
$-2,-3,\ldots$.

\sendindex{Real Numbers}
\sneakhead{Real Numbers}

Numbers in many scientific computations will grow in magnitude well beyond
the range of integers described above.  To provide for this, DEC System-20
and most scientific computers have a second way to represent numbers ---
the so-called {\sl floating-point representation}.  The significance
of the name ``floating-point'' is that the {\sl{radix point}} --- for example,
the decimal point in base-10 numbers --- is permitted to float to the right
or left, thus permitting scaling of numbers by various powers of the radix.
Although a decimal point that has floated off to the left will produce a number 
written like 0.001345, the numbers are actually represented in a form closer
to what is often called {\sl scientific notation}, here $.1345\times10↑{-2}$.

In DEC Sytem-20 floating-point numbers are represented in base-2 notation, i.e., 
the radix or number base is 2.  As in the case of integers, bit 0 (the leftmost
bit) represents the sign, 0 for positive and 1 for negative.  The remaining
35 bits represent an 8-digit exponent and a 27-bit fraction.  Bits 9 to 35 are 
interpreted as a binary fraction, i.e., 27 binary digits with a binary point
at the left-hand end.  This part is called the {\sl mantissa}.

Bits 1 to 8 are interpreted as an integral exponent in excess $128 (200↓8)$ code.
This means that bits 1--8 may be thought of as giving the binary (base-2)
representation of a nonnegative integer in the range $0↓{10}$ to $255↓{10}$,
inclusive.  This integer is called the {\sl biased exponent} for reasons now to
be explained.  If this integer were taken directly as the exponent, we would have
no negative exponents, and our range of floating-point numbers could not include
such numbers as $2↑{-100}$.  It is desirable to have an exponent range which is
approximately symmetric about zero.  One obtains the {\sl true exponent} of the
floating-point number by subtracting 128 from the biased exponent represented by
bits 1 to 8; this explains the name, excess 128 code.  As a result, the true
exponents range from ${-128}$ to 127.

As noted above, the 27 bits 9 to 35 are regarded as a binary fraction with a 
binary point at the left-hand end.  If the floating number zero is being 
represented all the bits are 0.  Otherwise, at least one of the binary digits
must be nonzero.  A floating-point number is said to be {\sl normalized}
if the left-hand binary digit (the most significant digit), bit 9, is 1.  In
DEC System-20 the floating-point numbers are ordinarily normalized and we shall
not consider any other forms.  Hence, the mantissa, M, may be positive or
negative and its magnitude lies in the range $1/2 ≤ \leftv M\rightv < 1$.

Negative floating-point numbers are stored in two's complement form.  Thus a
negative number has a 1 for its sign and the two's complement of the remaining 
bits.  Since every fraction (except zero) ordinarily contains a 1, it has the 
one's complement of the exponent code in bits 1 to 8.

We now give the floating-point representation of some sample numbers.  As we
said before, the number zero is represented by 36 zero bits.  Thus zero is 
represented by the same word in floating-point or integer form.  No other
number has this property.  The number 1.0 is represented by the word


%\def \threecolalign#1{$$\vbox{
%\halign{##\hfill⊗\qquad##\hfill⊗\qquad##\hfill\cr #1}}
%$$}
%\ctr{\vbox{\halign{\hfill#\ ⊗{#}\ ⊗{#}\cr
% This was originally a threecolalign.  Because of funniness with
% the upbrace I changed it by copyin and modifying the body
% results below.  -DPB 6/23/80

$$\vbox{\halign{#\hfill⊗\qquad#⊗#\hfill⊗\qquad#⊗#\hfill\cr
0⊗⊗10 000 001⊗⊗100 000 000 000 000 000 000 000 000\cr
$\up$⊗⊗\upbrace⊗⊗\upbrace\cr
sign⊗⊗\ctr{biased}⊗⊗\ctr{mantissa}\cr
bit⊗⊗\ctr{exponent}⊗⊗\cr
}}$$

%\threecolalign{
%0⊗10 000 001⊗100 000 000 000 000 000 000 000 000\cr
%$\up$⊗\upbrace⊗\upbrace\cr
%sign⊗\ctr{biased}⊗\ctr{mantissa}\cr
%bit⊗\ctr{exponent}⊗\cr
%}%end of threecolalign

\noindent
To check this, note the sign is 0 (representing +).  The biased exponent is
$10000001↓2$ or $129↓{10}$.  Subtracting $128↓{10}$ yields 1 as the true 
exponent.  Putting a binary point at the left of the mantissa gives the
binary fraction whose value is $1\over2$.  (This binary fraction could be
written more concisely in octal form as $.400000000↓8$.)  Thus the above
word represents $+(1/2)\times2=1.0$.  To save writing, the above word may be
written in octal form $201400000000↓8$.  The number $-1.0$ is represented by the 
word

%\ctr{\vbox{\halign{\hfill#\ ⊗{#}\ ⊗{#}\cr
\threecolalign{
1⊗01 111 110⊗100 000 000 000 000 000 000 000 000\cr
$\up$⊗\upbrace⊗\upbrace\cr
sign⊗\ctr{biased}⊗\ctr{mantissa}\cr
bit⊗\ctr{exponent}⊗\ctr{(2's complement)}\cr
⊗\ctr{(1's complement)}⊗\cr
}%end threecolalign

\noindent
To check this, note that the sign is 1 (representing $-$).  The biased exponent
(after taking one's complement) is $10000001=129↓{10}$ and the true exponent
is 1.  Taking the two's complement of the mantissa we see that it is unchanged
(in this example) and its value is $1/2$.  Thus the above word represents
$-({1\over2})\times2=-1.0$.  It may be written in octal form $576400000000↓8$.

Several examples of floating-point numbers are now given in octal notation,
with the confirmation left to the reader.
$$\halign{\hfill#⊗#\hfill⊗\qquad#\qquad⊗#\hfill\cr
\under{decimal}⊗⊗⊗\under{floating-point}\ (octal notation)\cr
0.0⊗⊗=⊗000000000000\cr
1.0⊗⊗=⊗201400000000\cr
-1.0⊗⊗=⊗576400000000\cr
23.0⊗⊗=⊗205560000000\cr
-23.0⊗⊗=⊗572220000000\cr
0.0⊗625⊗=⊗175400000000\cr
-0.0⊗625⊗=⊗602400000000\cr
16.0⊗⊗=⊗205400000000\cr
-16.0⊗⊗=⊗572400000000\cr
256.0⊗⊗=⊗211400000000\cr
-256.0⊗⊗=⊗566400000000\cr
3.5⊗⊗=⊗202700000000\cr
-3.5⊗⊗=⊗575100000000\cr
153.0⊗⊗=⊗210462000000\cr
-153.0⊗⊗=⊗567316000000\cr}$$

Notice that in checking the negative numbers one can take the two's complement 
of the number in octal notation directly in the following way:

\bitem{take the 7's complement of all digits to the left of the lowest
order non-zero digit (i.e., subtract each digit from 7)}
\bitem{take the 8's complement of the lowest order non-zero digit.}

\vskip 22pt

The largest floating-point number is 
$377777777777↓8$ representing $2↑{127}\times(1-2↑{-27})=.170\times10↑{39}$.  
The smallest positive floating-point number is $000400000000↓8$ represemting
$2↑{-129}=.14693\times10↑{-38}$.
The negatives of these
two numbers are the extremes in magnitude of representable negative numbers.  
They are represented by $400000000001↓8$ and $777400000000↓8$ respectively.
Since $2↑{-27}$ is approximately equal to $19↑{-8}$, the precision of a 27
bit binary number is approximately $10↑{-8}$.  Thus 27 binary bits are roughly
equivalent to 8 decimal digits.  For Pascal at LOTS the default condition for
a WRITE or WRITELN command causes real numbers to be printed out in the form
$x.xxxxxxxxxE{\pm}yy$.  That is, there are 9 digits to the right of the
decimal point and one digit to the left of the decimal point.  Here 
$yy$ denotes the power of 10 which multiplies the printed mantissa.  We may 
therefore expect that the rightmost two digits of the mantissa are not
reliable.

Very few numbers can be represented exactly with 8 decimal digits.  For
example, ${1\over80}=.012500000↓{10}$ is exactly represented, but ${1\over3}=.33333333↓{10}$
only approximately.  In the same way very few numbers can be exactly
represented with 27 binary digits (9 octal digits).  For example,
${1\over8}=.100000000↓8$ is excatly represented, but $1\over3 = .252525253↓8$
only approximately.  Moreover, some numbers that are
exactly representable in decimal are only approximately representable in binary;
for example, ${1\over10}=.10000000↓{10}$ exactly but ${1\over10}=.063146315↓8$ 
only approximately.

Conversely, some numbers that are exactly representable by 27 binary digits
are only approximately representable by 8 decimal digits (or even by 10
decimal digits as used in the default used in printing real numbers in Pascal).
For example, the floating-point number closest to 1.0 and above 1.0 has
a mantissa $$M=.400000001↓8$$ and an exponent 1.  Its value is 
$$1+2↑{-26}=1.000\ 000\ 014\ 901\ 161\ 193\ 847\ 656\ 25↓{10}$$
The default write command in Pascal produces 1.0000000014.  But by using the 
format parameter to cause this number to be printed with 26 digits to the
right of the decimal point, the exact value given above is obtained.  The
floating-point number closest to 1.0 and below 1.0 has a mantissa
$$m=.7777777777↓8$$
and an exponent 0.  Its value is
$$1-2↑{-27}=0.999\ 999\ 992\ 549\ 419\ 403\ 076\ 171\ 875.$$

The default write command in Pascal produces 9.999999880E-01.  But by using 
the format parameter to cause this number to be printed with 26 digits to the 
right of the decimal point, the value 
$$0.999\ 999\ 988\ 079\ 071\ 044\ 921\ 875\ 00$$
is obtained.  This result agrees with the true value in its first 7 digits
only.  Even more surprising is the fact that when $1+2↑{-27}$ is printed with
either 9 or 26 digits to the right of the decimal point, the result is 
identical with the value for $1+2↑{-26}$.  Also, when $1-2↑{-26}$ is printed
in either of these forms its value is identical with the value for 
$1-2↑{-27}$.

Thus round-off enters into the representation of most floating-point numbers
on DEC System-20 and the round-off differs from that with decimal numbers.  This
can can easily give rise to unexpected results.

It is of interest to note that $.700000000↓{10}$, when printed by the default 
WRITE command appears as 6.999999642 E-01 showing that conversion to binary
form and reconversion to decimal form for printing introduces some errors.
Because of round-off error, it is dangerous to compare reals in Pascal for
equality.  For example, if 
$$product := 700.* \ .700$$
the boolean expression
$$product = 490$$
would be FALSE.

\sendindex{Pascal Arithmetic}
\sneakhead{Pascal Arithmetic}

When doing arithmetic with integers in Pascal, the operations, +, $-$, *, either
give exact integer results, or else result in integers too long to store in
35 bits (overflow) and cause an error halt.  The division operation, {\tt DIV}
and the remainder operation, {\tt MOD}, can only be applied to integer operands and 
they give exact integer results.  When the division operation, /, is applied 
to integers in Pascal, the integers are first converted to real floating-point
numbers and the resulting quotient is real.

When arithmetic is done with real numbers in PASCAL, the exact result may
not be representable by 27 binary bits.  If the result is too large
(overflow) or too small (underflow) an error halt occurs with a message 
\wuncode{ARITHMETIC OVERFLOW OR ZERODIVIDE.}
\sendnotes{==>RWF - Is this always true-check out}
If it cannot be represented exactly,
it is rounded to 27 bits (in normalized form) giving the closest
representable number.  If the true result is $X$, then the calculated
result is always between $X(1-2↑{-28})$ and $X(1+2↑{-28})$.  Naturally the
accumulation of these small errors throughout the steps of the program may
give rise to large errors in the final result.

An integer value may be assigned to a real variable but a real value
cannot be assigned to an integer variable.  If {\tt X} is a real value, one
may  assign {\tt ROUND(X)} or {\tt TRUNC(X)} to an integer variable provided this
integer value does not exceed the maximum allowable integer value.

When an integer value, {\tt N}, is assigned to a real variable, if the
integer requires more than 27 bits of precision $(2↑{27}=134217728)$,
then some low order significance will be lost in the conversion to real;
otherwise, conversion to real and then back to integer using the
{\tt ROUND} or {\tt TRUNC} functions will result in the same integer value.  This means
that if an integer value is less than $2↑{27}$ it will be represented
exactly as a floating-point number.  But even if the integer value exceeds
$2↑{27}$, it would be represented exactly if in its binary representation,
the leftmost and rightmost ones are not more than 26 positions apart.

When the two operands of a Pascal operation, +, $-$, *, / are of
different type, the integer operand is converted first to real type
so that the arithmetic is done with real numbers.

\appendix E. {Finding the Root of an Equation}
 
For what value of  $x$ is  $\cos(x) = x$?  I.e., 
$cos(x) - x = 0$.
$cos(0)-0$ is $1 > 0$.  $cos(\pi/2) - \pi/2$  is  $-{\pi/2}< 0$.  
Somewhere between,  
$cos(x)-x = 0$.  We plan to narrow down the range in which the desired $x$ lies,
by a factor of two at every step.  Given two numbers  $lo$ and $hi$, where we
know that $lo ≤ x$  (so $cos(lo) - lo ≥ 0$) and $hi ≥ x$ (so  
$cos(hi) - hi ≤ 0$), we take a number between them, $mid = (hi + lo)/2$,
and depending on whether $cos(mid) - mid  ≥ 0$ or $< 0$, we take $mid$ as
the new value of $hi$ or $lo$.  We continue this until $hi - lo$ is very small;
$x$ always lies between them.

\startcode
        BEGIN
        REAL LO, MID, HI;
        LO := 0;
        HI := 3.1416/2;
        WHILE HI-LO > 0.000001 DO
                BEGIN
                (* LO $<=$ X $<=$ HI, F(LO) $>=$ 0, F(HI) $<=$ 0*)
                MID := (HI$+$LO)/2;
                IF COS(MID)-MID $>=$ 0 THEN
                        LO := MID
                ELSE HI := MID
                (* HI-LO HAS DECREASED BY HALF*)
                END;
        WRITELN("X SUCH THAT COS(X) $=$ X IS", (HI$+$LO)/2)
        END
\endcode


The key to the above program is the invariant of the iteration:  every time
we go through it, we start with a number in  $lo$ which is less than the
desired $x$, and a number in $hi$ which is larger.  Knowing this, it is easy
to find a new value for one or the other which is still on the correct side
of $x$, but is closer.

In order to know that the program will terminate, we have to see that
eventually, the difference between $hi$ and $lo$ will get less than any
positive number.  (Actually, because of rounding errors, the difference may
only get down to about $10↑{-8}$ and just stay there; this is why the test
for termination was based on a number larger than $10↑{-8}$.)  It is very
important, when designing indefinite iterations, to be sure that they
won't go on forever.
\appendix F. {Numerical Calculus}

In pure mathematics, when you have determined the sum of an infinite
series, you've said it all: 
$$\sum↑\infty↓{i=1}{1\over{i↑2}} = {\pi↑2\over6},$$ say.  
If you want to find a good approximate value for 
$\pi↑2/6$ from this series, perhaps by evaluating
$$\sum↑n↓{i=1}{1\over{i↑2}}$$ for some large {\tt n}, you find that the error
is large unless {\tt n} is very large.  The error is
$$\sum↑\infty↓{i=n+1}{1\over i↑2}\approx{\int↑\infty↓n}{x↑{-2}dx} = {1\over{n}}.$$
To get six-place accuracy, we need to 
have $n$ around $2\times10↑6$.  But then, we find that the accumulated
rounding errors of about $10↑{-8}$ per addition (on the DEC System 20)
have left our results wrong by about
\sendnotes{DPB->RWF: check forumulae}
$(2\times10↑6)\times10↑{-8}=2\times10↑{-2}$,
so we are
very far off.  To use computers to calculate numbers defined by limits,
we have to not only to approach the limits, but approach them fast enough
that we can get the result in reasonable time, without accumulating too
many small errors along the way.

The analysis above shows that
$$\sum↑n↓{i=1}{1\over{i↑2}}\approx S+{a\over n},\quad (\approx \hbox{\rm means ``is close to''})$$
where $S = {\pi{↑2}/6}$ and $a$ is some constant.  A more careful analysis 
would show that
$$\sum↑n↓{i-1}{1\over{i↑2}}\approx S+{a\over n}+{b\over{n↑2}}+{c\over n↑3} + \cdotss;$$
that is, the error in using the finite sum is a convergent series of powers of
$1/n$ in which all terms go to zero as $n$ gets large.  If we could get
rid of the term $a/n$, we would have a much smaller error for large $n$.

Define
$$S↓0(n) = \sum↑n↓{i=1}{1\over{i↑2}} = S + {a\over n} + {b\over{n↑2}} + {c\over{n↑3}} + \cdotss.$$
Then $S↓0(2n)$, summing twice as many terms, is
$$S + {a\over{2n}} + {b\over{4n↑2}} + {c\over{8n↑3}} + \cdotss.$$
Eliminating $a$ between $S↓0(n)$ and $S↓0(2n)$, we define
$$S↓1(n) = 2S↓0(2n) - S↓0(n) = S - {1\over2}{b\over{n↑2}} - {3\over4}{c\over{n↑3}} - \cdotss.$$
so $S↓1(n)$ approaches $s$ much faster than $S↓0(n)$ does.
Now 
$$S↓1(2n) = S - {1\over8}{b\over{n↑2}} - {3\over{32}}{c\over{n↑3}} - \cdotss,$$
and we can elminate $b$ between
$S↓1(n)$ and $S↓1(2n)$:
$$S↓2(n) = {4S↓1(2n) - S↓1(n)\over3} = S + \hbox{terms in}\  {1/n↑4}.$$
Another step gives:
$$S↓3(n) = {{8S↓2(2n) - {S↓2(n)}\over7}} = S + \hbox{terms in}\  {1/n↑6}$$
\sendnotes{DPB->RWF: check "terms in" in both places.}
Using $n = 4$, we get, using a pocket calculator for ten minutes,
$$\halign{$\ctr{#}$\quad⊗$\ctr{#}$\quad⊗$\ctr{#}$\quad⊗$\ctr{#}$\cr
S↓0(n) = 1.4236111⊗S↓1(n) = 1.6312732⊗S↓2(n) = 1.6446036⊗S↓3(n) = 1.6449350\cr
S↓0(2n) = 1.5274221⊗S↓1(2n) = 1.6412710⊗S↓2(2n) = 1.6448936\cr
S↓0(4n) = 1.5843465⊗S↓1(4n) = 1.6439880\cr
S↓0(8n) = 1.6141672\cr
}$$%end halign
where $S↓3(n) - {\pi↑2/6} = .0000009$, as small an error as if we had
evaluated 
$$\sum↑{10↑6}↓{i=1}{1\over i↑2}$$
using twelve- or thirteen-digit numbers.

This is not necessarily the best way to evaluate $\pi↑2/6$, and it
works very badly on some other infinite series so it should not be used
generally; it shows, however, that calculus with actual numbers involves
an ingredient not present in the pure calculus:  finding ways to achieve
very high precision with very little computation.

\exercise
Program the analogous computation of $\ln(2)$
$$\eqalign{\ln(2)⊗= 1-{1\over2}+{1\over3}-{1\over4}+{1\over5}-{1\over6}\ldots\cr
⊗={1\over2}+{1\over{12}}+{1\over{20}}+\cdotss+{1\over{(2i-1)2i}}+\ldotss\cr}$$
with $$S↓0(n) = \sum↑n↓{i=1}{1\over{(2i-1)2i}}$$ up to $S↓4(5)$.  Print out each
$S↓{j}(5)$, and its difference from $\ln(2)$.
\endexercise

\vskip 11pt

We could calculate an integral in a similar way.  We can approximate
$$I = {\int↑1↓0}f(x)\,dx$$ by 
$$I↓0(n) = {1\over n}\sum↑{n-1}↓{i=0}f\left({i+{1\over2}}\over n\right).$$

$$I↓0(n) = I + {a\over{n↑2}} + {b\over{n↑4}} + {c\over{n↑6}} + \cdotss$$

See if you can work out an analogous method for computing the integral
accurately without too many evaluations of $f$.  (Idea:  try eliminating $a$ between 
$I↓0(n)$ and $I↓0(3n)$.  Notice that the sum in
$I↓0(n)$ is a part of the sum in $I↓0(3n)$.)  Try it out on
$${\int↑1↓0}{e↑{-x↑2/2}\,dx} = 0.3413\ldotss$$